// $Id: dispatcher.h 86 2011-05-04 17:33:43Z cedric.shih@gmail.com $
/*
 * Copyright (C) 2011 Cedric Shih <cedric.shih@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef DISPATCHER_H_
#define DISPATCHER_H_

#include "context.h"
#include "future.h"

struct niohttpd_streams;

struct niohttp_response;

struct niohttpd_dispatcher {
	const char *name;
	struct niohttpd *server;
	struct niohttp_request_decoder *decoder;
	struct niohttp_response_encoder *encoder;
	struct niobuffer *header;
	struct niobuffer *wrapper;
	struct niohttpd_handler *handler;
	struct niohttpd_context context;
	struct niohttpd_future future;
};

struct niohttpd_dispatcher *niohttpd_dispatcher_new(struct niohttpd *server);

void niohttpd_dispatcher_free(void *obj);

struct niohandler niohttpd_dispatcher;

int niohttpd_dispatcher_setup(void *obj, const char *name);

int niohttpd_dispatcher_teardown(void *obj);

struct niochannel;

int niohttpd_dispatcher_handle_upstream(void *obj,
		struct niochannel *channel, void *message);

int niohttpd_dispatcher_handle_downstream(void *obj,
		struct niochannel *channel, void *message);

struct niohttpd_handler niohttpd_404_handler;

struct niohttpd_context;

struct niohttpd_future;

int niohttpd_404_handler_on_replyable(struct niohttpd_context *context,
		struct niohttpd_future *future, void *arg);

#endif /* DISPATCHER_H_ */
